package com.wgy.day41JDBC.抽取JDBC工具类;

import java.sql.*;

/**
 * Created by pc on 2020/12/23 23:19
 * Description: LearningJava
 */
public class Demo09JDBCUtils演示 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {
            //2.定义sql
            String sql = "select * from account ";

            //3.获取connection对象
            conn=JDBCUtils.getConnection();

            //4.获取执行sql的对象statement
            stmt = conn.createStatement();
            //5.执行sql,接收返回值结果
            rs = stmt.executeQuery(sql);//resultSet:结果集
            //6.处理结果
            //6.1让结果集的游标向下移动一行,
            // 循环判断当前行是否有数据,有就获取
            while (rs.next()) {
                //6.2获取数据
                int id = rs.getInt(1);
                String name = rs.getString("name");
                double balance = rs.getDouble("balance");
                System.out.println(id + "---" + name + "---" + balance);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }  //7.释放资源
        finally {
            JDBCUtils.close(rs, stmt, conn);

        }
    }
}